home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / demos / bobtest.c next >
C/C++ Source or Header  |  1986-01-15  |  6KB  |  222 lines

  1. /* bobtest.c AmigaLink 1/25/86 */
  2. /****************************************************************
  3. *                         BOBTEST.C                             *
  4. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  5. * No part of this program may be reproduced, transmitted,       *
  6. * transcribed, stored in retrieval system, or translated into   *
  7. * any language or computer language, in any form or by any      *
  8. * means, electronic, mechanical, magnetic, optical, chemical,   *
  9. * manual or otherwise, without the prior written permission of  *
  10. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  11. * Los Gatos, CA 95030                                           *
  12. *                                                               *
  13. ****************************************************************/
  14. /* PROGRAM TO PUT UP A BLOCK-BOB IN A WINDOW AND BOUNCE IT AROUND A BIT */
  15.  
  16. /* Author: Rob Peck  9/10/85 */
  17. /* Modified: Randy Weiner  1/16/86 -- permit closing window/ending program*/
  18.  
  19. #include <exec/types.h>
  20. #include <graphics/gfx.h>
  21. #include <graphics/rastport.h>
  22. #include <graphics/view.h>
  23. #include <exec/exec.h>
  24. #include <graphics/gels.h>
  25. #include <intuition/intuition.h>
  26.  
  27. #define DEPTH 3
  28.  
  29. long GfxBase = 0;
  30. long IntuitionBase=0;
  31.  
  32. VOID test2();
  33. struct Window *OpenWindow();
  34. struct InputEvent *Intuition();
  35. struct Screen *OpenScreen();
  36. struct RastPort *CDRastPort();
  37. struct Message *GetMsg();
  38.  
  39. struct Window *w;
  40. struct Screen *screen;
  41. struct RastPort *rp;
  42. struct ViewPort *vp;
  43.  
  44. struct TextAttr TestFont = { "topaz.font", 9, 0, 0 };
  45.  
  46. struct NewScreen ns = {
  47. 0, 0,                    /* left edge, top edge */
  48. 640, 200, DEPTH,         /* width, height    */
  49. 0, 1,                    /* detail pen, block pen */
  50. HIRES,                   /* viewing mode     */
  51. CUSTOMSCREEN,            /* screen type */
  52. &TestFont,               /* font to use */
  53. "Gels Test Program",          /* default title for screen */
  54. NULL                /* pointer to additional gadgets */
  55. };
  56.  
  57. struct NewWindow nw = {
  58. 20, 20,                  /* left edge, top edge */
  59. 220, 150,           /* width, height */
  60. -1, -1,                  /* detail pen, block pen*/
  61. CLOSEWINDOW,             /* IDCMP flags */
  62.                     /* window flags */
  63. GIMMEZEROZERO|WINDOWDRAG|WINDOWSIZING|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|
  64. ACTIVATE|NOCAREREFRESH,
  65. NULL,                    /* pointer to first user gadget */
  66. NULL,                    /* pointer to user checkmark    */
  67. "Big Bob",               /* window title */ 
  68. NULL,                    /* pointer to screen(later)*/
  69. NULL,                    /* pointer to superbitmap */
  70. 10,10,300,160,           /* max size of window */
  71. CUSTOMSCREEN             /* type of screen in which to open */
  72. };
  73.  
  74.  
  75. main()
  76. {
  77.  
  78.    GfxBase = OpenLibrary("graphics.library", 0);
  79.    if (GfxBase == NULL)
  80.    {
  81.       printf("Unable to open graphics library\n");
  82.       exit(1000);
  83.       }
  84.  
  85.    IntuitionBase = OpenLibrary("intuition.library", 0);
  86.    if (IntuitionBase == NULL)
  87.    {
  88.       printf("Unable to open intuition library\n");
  89.       exit(1000);
  90.       }
  91.  
  92.    screen = OpenScreen(&ns);       /* make a custom screen */
  93.    nw.Screen = screen;
  94.  
  95.    w = OpenWindow(&nw);            /* open a window */
  96.    rp = w->RPort;             /* get address of rastport */
  97.    vp = &w->WScreen->ViewPort;          /* and viewport  */
  98.  
  99.    test2();         /* returns when close gadget is selected */
  100.    CloseWindow(w);
  101.    CloseScreen(screen);
  102.  
  103. }
  104.  
  105. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  106.  
  107. struct VSprite s1, s2;        /* dummy sprites for gels list */
  108. struct GelsInfo gelsinfo;     /* gelsinfo to link into system rastport */
  109. struct collTable collisiontable;
  110.  
  111. struct VSprite v;
  112. struct Bob b;
  113.  
  114. SHORT i;
  115.  
  116. SHORT collmask[5 * 42];
  117. SHORT borderline[5];
  118.  
  119. SHORT savebuffer[5 * 42 * 3];
  120. SHORT dummy[ 1 * 42 * 3 ];/* in case for some reason system needs
  121.  * one extra word per line to properly
  122.  * perform the save 
  123.  */
  124.  
  125. SHORT xspeed;
  126. SHORT yspeed;
  127. SHORT *images;
  128.  
  129. VOID test2()
  130. {
  131.    SHORT *j;
  132.    BOOL exit_loop;
  133.    struct IntuiMessage *m1;
  134.  
  135.    gelsinfo.nextLine = NULL;
  136.    gelsinfo.lastColor = NULL;
  137.    gelsinfo.collHandler = &collisiontable;
  138.  
  139.    InitGels(&s1, &s2, &gelsinfo);
  140.    rp->GelsInfo = &gelsinfo;
  141.  
  142.    xspeed = 2;
  143.    yspeed = 4;
  144.  
  145.    v.X = 20;
  146.    v.Y = 20;
  147.    v.Flags = OVERLAY | SAVEBACK;
  148.    v.Height = 42;             /* 42 lines high */
  149.    v.Width = 5;               /* 5 words per row is 80 bits */
  150.    v.Depth = 3;               /* 3 planes deep, will use same for
  151.  *                     its playfield */
  152.    v.MeMask = 1;
  153.    v.HitMask = 1;
  154.  
  155. /* Set value of image to the proper area of the loaded data */
  156.  
  157.    images = (SHORT *)AllocMem(32000, MEMF_PUBLIC + MEMF_CLEAR);
  158.    j = images;
  159.    for(i=0; i< 16000; i++) 
  160.       *j++ = 0xaa3c;          /* image data */
  161.  
  162.    v.ImageData = (images + 20); 
  163.    v.CollMask = &collmask[0];
  164.    v.BorderLine = &borderline[0];
  165.  
  166.    InitMasks(&v);
  167.  
  168.    v.PlanePick = 0x07;/* pick 3 planes */
  169.    v.PlaneOnOff = 0x0;/* all zeros to others if any */
  170.  
  171. /* ****************** now initialize the Bob variables ******* */
  172.  
  173.    b.Flags = 0;
  174.    b.SaveBuffer = &savebuffer[0];  /* show where to save background */
  175.    b.ImageShadow = &collmask[0];   /* collision and shadow are same */
  176.    b.Before = NULL;           /* dont care about drawing order */
  177.    b.After = NULL;
  178.  
  179.    b.BobComp = NULL;               /* not animation component */
  180.    b.DBuffer = NULL;               /* not double buffered */
  181.  
  182.    b.BobVSprite = &v;              /* link them together */
  183.    v.VSBob = &b;
  184.  
  185.    AddBob(&b, rp);
  186.    SortGList(rp);
  187.    WaitTOF();
  188.    DrawGList(rp,vp);
  189.  
  190.    exit_loop = FALSE;
  191.    while (!exit_loop) {
  192.  
  193.       b.BobVSprite->Y += yspeed;
  194.       if(b.BobVSprite->Y > 100 || b.BobVSprite->Y < 10)
  195.      yspeed = -yspeed;
  196.       b.BobVSprite->X += xspeed;
  197.  
  198. /*  change these limits to increase x-travel of BOB */
  199.       if(b.BobVSprite->X > 200 || b.BobVSprite->X < 10)
  200.      xspeed = -xspeed;
  201.  
  202.       SortGList(rp);
  203.       WaitTOF();
  204.       WaitTOF();
  205.       DrawGList(rp,vp);
  206.  
  207. /* Check to see if any IDCMP signal bit is set. If so, and if its
  208.  * the CLOSEWINDOW bit, clean up and exit
  209.  */
  210.       if (1<<w->UserPort->mp_SigBit) {
  211.  
  212.      while ( (m1=(struct IntuiMessage *)GetMsg(w->UserPort))) {
  213.         if ( m1->Class == CLOSEWINDOW)
  214.           exit_loop = TRUE;
  215.         ReplyMsg(m1);       
  216.            }
  217.      }
  218.    }
  219.    FreeMem(images,32000);
  220.  
  221. }
  222.